#pragma once
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>
#include "base.h"
#include "Types.h"
#include "TextureManager.h"
#include "MultiTextureIndex.h"
#include "BlockLibrary.h"
#include "BlockModel.h"
#include "ICamera.h"
#include "IRenderer.h"
#include "Chunk.h"

//Shaders
#include "SolidBlockShader.h"

typedef boost::shared_array<vector3> VertexArray;
typedef boost::shared_array<uint> IndexArray;
class BlockRenderer
{
public:
	BlockRenderer(void);
	~BlockRenderer(void);
	void Initialize(BlockLibrary *pBlocks, IRenderer *pRenderer);
	void SetTerrainTexture(uint nTex);

	//Drawing functions
	/*
	void BeginBlockDrawing(const matrix &projection, const matrix &view, uint nTerrainTexture);
	void DrawBlock(vector3 &position, uint blockID);
	void EndBlockDrawing();*/
	//Alternative drawing
	void BeginBlockDrawingAlt();
	void EndBlockDrawingAlt();
	void DrawBlockAlt(vector3 position, uint blockID);
	void DrawChunkBlocksInstanced(Chunk *pChunk);

	void SetCamera(boost::shared_ptr<ICamera> pCamera);
	boost::shared_ptr<ICamera> GetCamera();

	TextureManager *GetTextureManager();
protected:
	inline void DrawSide(uint sideId, const uint* indexBuffer,
		const MultiTextureIndex &mti);
private:
	int m_pnSideVisibility[SIDE_COUNT];
	SolidBlockShader m_shaderSolid;
	BlockModel m_blockModel;
	BlockLibrary *m_pBlocks;
	TextureManager *m_pTextures;
	boost::shared_ptr<ICamera> m_pCamera;
	IRenderer *m_pRenderer;
	uint m_nTerrainTexture;
};